package org.example.petitionplatformsystem.controller;

import org.example.petitionplatformsystem.Response;
import org.example.petitionplatformsystem.dto.PetitionDTO.StatusApprovalDTO;
import org.example.petitionplatformsystem.service.ComplaintStatusService;
import org.example.petitionplatformsystem.utils.IntToStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/consulting")
public class complaintStatusController {
    //信访状态表的服务
    private final ComplaintStatusService complaintStatusService;
    @Autowired
    public complaintStatusController(ComplaintStatusService complaintStatusService){
        this.complaintStatusService = complaintStatusService;
    }

    @GetMapping("/{petitionid}/getStatus")
    public Response<List<StatusApprovalDTO>> getStatus(@PathVariable("petitionid") long petitionid) {

        List<Integer> statusNumberList = complaintStatusService.getPetitionAllStatus(petitionid);
        List<String> dataList = complaintStatusService.getPetitionAllStatusData(petitionid);
        System.out.println("status_number: " + statusNumberList);

        List<String> statusList = IntToStringUtil.getStatusStrings(statusNumberList);
        List<StatusApprovalDTO> petitionStatusList = new ArrayList<>();
        for (int i = 0; i < statusList.size(); i++) {
            petitionStatusList.add(new StatusApprovalDTO(statusList.get(i), dataList.get(i)));
        }

        return Response.newSuccessResponse(petitionStatusList);
    }

}

